

import 'package:aqua_plunge/http/app_manager.dart';
import 'package:aqua_plunge/model/listItem.dart';
import 'package:aqua_plunge/model/userinfo.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

import '../dao/broadcaster_dao.dart';
import '../model/followItem.dart';

class UserController extends GetxController{

   final _userInfo = UserInfo().obs;

   get userInformation => _userInfo.value;

   var followingNum = 0.obs;
   var blockNum = 0.obs;
   var followingList = <FollowItem>[].obs;
   var blockList = <listItem>[].obs;

   Future<void> fetchUserData() async{
     try{
       _userInfo.value = AppManager.getUserInfo();
     }catch(error){
       debugPrint(error.toString());
     }
   }

  void updateInfo() async{
     _userInfo.value = await BroadCasterDao.getUserInfo(AppManager.getUserInfo().userId??'0');
     updateFollowBlock();
  }

  updateFollowBlock() async{
      followingList.value = await BroadCasterDao.friendslist();
      blockList.value = await BroadCasterDao.blocklist();
      followingNum.value = followingList.length;
      blockNum.value = blockList.length;
  }

}